/***************************************************************
|	File:		AnchorPointAnimation.h
|	Author:		
|	Course:		
|	Purpose:	AnchorPointAnimation class runs a variable-size 
|				animation, storing the source rects for each frame
|				and an 'anchor-point' == relative position
***************************************************************/

#pragma once

#include "Animation.h"

#include "../SGD Wrappers/SGD_GraphicsManager.h"
#include <vector>
#include <cassert>


/**************************************************************/
// AnchorPointAnimation class
//	- runs animation using an image of variable-size frames
//	- stores a relative offset from the top-left corner of the frame rect 
//	  to the render position
//	- image MUST have a size power-of-2 (e.g. 64, 128, 256, 512)
class AnchorPointAnimation : public Animation
{
public:
	/**********************************************************/
	// Default Constructor & Destructor
	AnchorPointAnimation()	= default;
	~AnchorPointAnimation()	= default;
	

	/**********************************************************/
	// Initialize & Terminate
	void	Initialize	( const char * _filename );
	void	Terminate	( void );


	/**********************************************************/
	// Animation Controls:
	void	Update		( float elapsedTime );
	void	Render		( SGD::Point position, bool flipped,
						  float scale, SGD::Color color );
	
	SGD::Rectangle GetRect( SGD::Point position, bool flipped,
						  float scale ) const;	

private:
	// frame data
	struct Frame
	{
		SGD::Rectangle		rFrame;		// source rectangle
		SGD::Point			ptAnchor;	// relative position within source
		float				fDuration;	// time to wait on this frame
	};

	std::vector< Frame >	m_vFrames;

};
